﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace ParseXAML
{
    public enum eType { XAML, RESX, Code };

    public interface IOutput
    {
        eType Type { get; }
        string FileName { get; }
        void Save();
    }

    public class Outputs : List<IOutput>
    {
        public void Save()
        {
            foreach (var o in this)
                o.Save();
        }
    }

    internal abstract class Output : IOutput
    {
        public eType Type { get; set; }
        public string FileName { get; set; }

        public Output(eType Type, string FileName)
        {
            this.Type = Type;
            this.FileName = FileName;
        }

        public abstract void Save();
    }

    internal class XAMLOutput : Output
    {
        XmlDocument doc;

        public XAMLOutput(XmlDocument doc, eType Type, string FileName)
            : base(Type, FileName)
        {
            this.doc = doc;
        }

        public override void Save()
        {
            doc.Save(this.FileName);
        }
    }

    internal class StringOutput : Output
    {
        string doc;

        public StringOutput(string doc, eType Type, string FileName)
            : base(Type, FileName)
        {
            this.doc = doc;
        }

        public override void Save()
        {
            using (System.IO.FileStream fw = new System.IO.FileStream(this.FileName, System.IO.FileMode.Create))
            {
                System.IO.StreamWriter sw = new System.IO.StreamWriter(fw);
                sw.Write(this.doc);
                sw.Flush();
            }
        }
    }

}
